Let |a| = n.  Then  if and only if

gcd(n,i) = gcd(n,j).